package com.zelin.servlet;

import com.zelin.pojo.Student;
import com.zelin.service.StudentService;
import com.zelin.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: ZhangXiaoHan
 * @Date: 2020/09/26/19:52
 * @Description:
 */
@WebServlet("/student")
public class StudentServlet extends HttpServlet {
    private StudentService studentService = new StudentServiceImpl();

    /**
     * 查询学生表
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //查询学生表
        List<Student> list = studentService.find();
        //放到请求域中
        request.setAttribute("list",list);
        //转发到页面
        request.getRequestDispatcher("/WEB-INF/student/list.jsp").forward(request,response);
    }
}
